<?php

namespace App\Task\Crontab;


use App\Dao\UserDao;
use App\Model\ImOnline;
use Hyperf\Crontab\Annotation\Crontab;

/**
 * Note - 自动统计在线人数(对应后台即时聊天在线人数)
 * DateTime 2024/9/2 14:02
 * User Admin
 * Class AutoStatOnlineTask
 * @package App\Task\Crontab
 */
class AutoStatOnlineTask
{
    // #[Crontab(rule: "* * * * * *", memo: "foo")]
    public function execute()
    {
        $male = UserDao::getInstance()->getOnlineUids(1);
        $female = UserDao::getInstance()->getOnlineUids(2);
        $data['man_count'] = count($male);
        $data['woman_count'] = count($female);
        $data['total'] = $data['man_count'] + $data['woman_count'];
        $data['ctime'] = time();
        $data['date'] = date('Y-m-d');
        ImOnline::insert($data);

    }
}
